define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/tongji/index' + location.search,
                    // add_url: 'user/tongji/add',
                    // edit_url: 'user/tongji/edit',
                    // del_url: 'user/tongji/del',
                    // multi_url: 'user/tongji/multi',
                    // import_url: 'user/tongji/import',
                    table: 'user_copy1',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible:true,

                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'username', title: __('Username'), operate: "LIKE"},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'nickname', title: __('Nickname'), operate: false},
                        {field: 'money_a', title: __('套餐A总金额'), operate: false},
                        {field: 'money_b', title: __('套餐B总金额'), operate: false},
                        {field: 'tca_num', title: __('套餐A购买人数'), operate: false},
                        {field: 'tcb_num', title: __('套餐B购买人数'), operate: false},
                        {field: 'money_all', title: __('金额合计'), operate: false},
                        {field: 'num_all', title: __('人数合计'), operate: false},
                        {field: 'createtime', title: __('时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
